﻿using System;
using System.Drawing;

namespace ThermoGroupSample {
    class Util {
        public static Point axesTransfer(int srcX, int srcY, int srcWidth, int srcHeight, int dstWidth, int dstHeight) {
            int x = srcX * dstWidth / srcWidth;
            int y = dstHeight - 1 - srcY * dstHeight / srcHeight;
            return new Point(x, y);
        }

        public static bool makeValueInRange(ref int val, int minVal, int maxVal) {
            bool isChanged = false;
            if (val < minVal) {
                val = minVal;
                isChanged = true;
            } else if (val > maxVal) {
                val = maxVal;
                isChanged = true;
            }
            return isChanged;
        }

        public static byte[] getUTF8Bytes(string name) {
            byte[] utf8Buffer = new byte[32];
            byte[] tempBuffer = System.Text.Encoding.UTF8.GetBytes(name);
            try {
                Array.Copy(tempBuffer, utf8Buffer, tempBuffer.Length);
            } catch (Exception) {
                utf8Buffer[0] = 0;
            }
            return utf8Buffer;
        }
    }
}
